package de.jabc.sib.bio.ebi;

import de.jabc.adapter.bio.ebi.Branches;
import de.jabc.adapter.bio.ebi.LightweightServiceAdapter;
import de.jabc.adapter.bio.ebi.ServiceAdapter;
import de.metaframe.jabc.framework.execution.ExecutionEnvironment;
import de.metaframe.jabc.framework.sib.annotation.SIBClass;
import de.metaframe.jabc.framework.sib.annotation.SIBStatus;
import de.metaframe.jabc.framework.sib.parameter.ContextExpression;
import de.metaframe.jabc.framework.sib.parameter.ContextKey;
import de.metaframe.jabc.sib.ServiceAdapterDescriptor;

/**
 * Calls the EBI's EMBOSS needle service.
 * 
 * @author anna-lena
 * @version $Revision: 3325 $ $Date: 2008-03-03 13:34:38 +0100 (Mon, 03 Mar
 *          2008) $
 */
@SIBClass("ebi-sibs/Needle")
@SIBStatus("IMPLEMENTED")
public class Needle extends AbstractSIB {

	/* Branches */
	public static final String[] BRANCHES = { Branches.DEFAULT, Branches.ERROR };

	/* Parameters */
	public ContextExpression Email = new ContextExpression("", String.class,
			false);
	public ContextExpression Title = new ContextExpression("", String.class,
			false);
	public ContextExpression Matrix = new ContextExpression("", String.class,
			false);
	public ContextExpression Gapopen = new ContextExpression("", String.class,
			false);
	public ContextExpression Gapextend = new ContextExpression("", String.class,
			false);
	public ContextExpression Endweight = new ContextExpression("", String.class,
			false);
	public ContextExpression Endopen = new ContextExpression("", String.class,
			false);
	public ContextExpression Endext = new ContextExpression("", String.class,
			false);
	public ContextExpression Format = new ContextExpression("", String.class,
			false);
	public ContextExpression Stype = new ContextExpression("", String.class,
			false);
	public ContextExpression Asequence = new ContextExpression("", String.class,
			false);
	public ContextExpression Bsequence = new ContextExpression("", String.class,
			false);
	public ContextKey resultOut = new ContextKey("resultOut", ContextKey.Scope.LOCAL,
			true);
	public ContextKey resultAln = new ContextKey("resultAln", ContextKey.Scope.LOCAL,
			true);
	
	/**
	 * @see de.metaframe.jabc.sib.CodeGeneratorBlock#execute(ExecutionEnvironment)
	 */
	public String execute(ExecutionEnvironment environment) {
		try {
			return ServiceAdapter.callNeedle(environment, this.Email,
					this.Title, this.Matrix, this.Gapopen, this.Gapextend, this.Endweight, this.Endopen,
					this.Endext, this.Format, this.Stype, this.Asequence, this.Bsequence, this.resultOut, this.resultAln);
		} catch (NoClassDefFoundError e) {
			return Branches.ERROR;
		}
	}

	/**
	 * @see de.metaframe.jabc.sib.Generatable#generate()
	 */
	public ServiceAdapterDescriptor generate() {
		return new ServiceAdapterDescriptor(LightweightServiceAdapter.class
				.getName(), "callNeedle", "Email", "Title", "Matrix", "Gapopen", "Gapextend", "Endweight",
				"Endopen", "Endext", "Format", "Stype", "Asequence", "Bsequence", "resultOut", "resultAln");
	}

}
